<!DOCTYPE html>
<html>
<!--
Copyright 2006 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<!--
  All Rights Reserved.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.i18n.DateTimeParse</title>
<meta charset="utf-8"/>
<script src="../base.js"></script>
<script>
  goog.require('goog.date.Date');
  goog.require('goog.i18n.DateTimeFormat');
  goog.require('goog.i18n.DateTimeParse');
  goog.require('goog.i18n.DateTimeSymbols');
  goog.require('goog.i18n.DateTimeSymbols_en');
  goog.require('goog.i18n.DateTimeSymbols_fr');
  goog.require('goog.i18n.DateTimeSymbols_zh');
  goog.require('goog.testing.ExpectedFailures');
  goog.require('goog.testing.jsunit');
  goog.require('goog.userAgent');
  goog.require('goog.userAgent.product');
</script>
</head>
<body>
<script>


goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_en;

var expectedFailures = new goog.testing.ExpectedFailures();

function tearDown() {
  expectedFailures.handleTearDown();
}

function testNegativeYear() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('MM/dd, yyyy');
  assertTrue(parser.parse('11/22, 1999', date) > 0);
  assertEquals(1999, date.getFullYear());
  assertEquals(11 - 1, date.getMonth());
  assertEquals(22, date.getDate());

  assertTrue(parser.parse('11/22, -1999', date) > 0);
  assertEquals(-1999, date.getFullYear());
  assertEquals(11 - 1, date.getMonth());
  assertEquals(22, date.getDate());
}

function testEra() {
  // Bug 2350397
  if (goog.userAgent.WEBKIT) {
  // Bug 2350397 Test seems to be very flaky on Chrome. Disabling it
    return;
  }

  var date = new Date();
  var parser = new goog.i18n.DateTimeParse('MM/dd, yyyyG');
  assertTrue(parser.parse('11/22, 1999BC', date) > 0);
  assertEquals(-1998, date.getFullYear());
  assertEquals(11 - 1, date.getMonth());
  assertEquals(22, date.getDate());

  assertTrue(parser.parse('11/22, 1BC', date) > 0);
  assertEquals(0, date.getFullYear());
  assertEquals(11 - 1, date.getMonth());
  assertEquals(22, date.getDate());

  assertTrue(parser.parse('11/22, 1999AD', date) > 0);
  assertEquals(1999, date.getFullYear());
  assertEquals(11 - 1, date.getMonth());
  assertEquals(22, date.getDate());
}

function testFractionalSeconds() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('hh:mm:ss.SSS');
  assertTrue(parser.parse('11:12:13.956', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(12, date.getMinutes());
  assertEquals(13, date.getSeconds());
  assertEquals(956, date.getTime() % 1000);

  assertTrue(parser.parse('11:12:13.95', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(12, date.getMinutes());
  assertEquals(13, date.getSeconds());
  assertEquals(950, date.getTime() % 1000);

  assertTrue(parser.parse('11:12:13.9', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(12, date.getMinutes());
  assertEquals(13, date.getSeconds());
  assertEquals(900, date.getTime() % 1000);
}

function testAmbiguousYear() {
  // assume this year is 2006, year 27 to 99 will be interpret as 1927 to 1999
  // year 00 to 25 will be 2000 to 2025. Year 26 can be either 1926 or 2026
  // depend on the time being parsed and the time when this program runs.
  // For example, if the program is run at 2006/03/03 12:12:12, the following
  // code should work.
  // assertTrue(parser.parse('01/01/26 00:00:00:001', date) > 0);
  // assertTrue(date.getFullYear() == 2026 - 1900);
  // assertTrue(parser.parse('12/30/26 23:59:59:999', date) > 0);
  // assertTrue(date.getFullYear() == 1926 - 1900);

  // Since this test can run in any time, some logic needed here.

  var futureDate = new Date();
  futureDate.setFullYear(futureDate.getFullYear() +
      100 - goog.i18n.DateTimeParse.ambiguousYearCenturyStart);
  var ambiguousYear = futureDate.getFullYear() % 100;

  var parser = new goog.i18n.DateTimeParse('MM/dd/yy HH:mm:ss:SSS');
  var date = new Date();

  var str = '01/01/' + ambiguousYear + ' 00:00:00:001';
  assertTrue(parser.parse(str, date) > 0);
  assertEquals(futureDate.getFullYear(), date.getFullYear());

  str = '12/31/' + ambiguousYear + ' 23:59:59:999';
  assertTrue(parser.parse(str, date) > 0);
  assertEquals(futureDate.getFullYear(), date.getFullYear() + 100);

  // Test the ability to move the disambiguation century
  goog.i18n.DateTimeParse.ambiguousYearCenturyStart = 60;

  futureDate = new Date()
  futureDate.setFullYear(futureDate.getFullYear() +
      100 - goog.i18n.DateTimeParse.ambiguousYearCenturyStart);
  ambiguousYear = futureDate.getFullYear() % 100;

  var str = '01/01/' + ambiguousYear + ' 00:00:00:001';
  assertTrue(parser.parse(str, date) > 0);
  assertEquals(futureDate.getFullYear(), date.getFullYear());


  str = '12/31/' + ambiguousYear + ' 23:59:59:999';
  assertTrue(parser.parse(str, date) > 0);
  assertEquals(futureDate.getFullYear(), date.getFullYear() + 100);

  // Reset parameter for other test cases
  goog.i18n.DateTimeParse.ambiguousYearCenturyStart = 80;
}

function testLeapYear() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('MMdd, yyyy');
  assertTrue(parser.parse('0229, 2001', date) > 0);
  assertEquals(3 - 1, date.getMonth());
  assertEquals(1, date.getDate());

  assertTrue(parser.parse('0229, 2000', date) > 0);
  assertEquals(2 - 1, date.getMonth());
  assertEquals(29, date.getDate());
}

function testAbutField() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('hhmm');
  assertTrue(parser.parse('1122', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('122', date) > 0);
  assertEquals(1, date.getHours());
  assertEquals(22, date.getMinutes());

  var parser2 = new goog.i18n.DateTimeParse('hhmmss');
  assertTrue(parser2.parse('112233', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());
  assertEquals(33, date.getSeconds());

  assertTrue(parser2.parse('12233', date) > 0);
  assertEquals(1, date.getHours());
  assertEquals(22, date.getMinutes());
  assertEquals(33, date.getSeconds());

  var parser3 = new goog.i18n.DateTimeParse('yyyyMMdd');
  assertTrue(parser3.parse('19991202', date) > 0);
  assertEquals(1999, date.getFullYear());
  assertEquals(12 - 1, date.getMonth());
  assertEquals(02, date.getDate());

  assertTrue(parser3.parse('9991202', date) > 0);
  assertTrue(date.getFullYear() == 999);
  assertEquals(12 - 1, date.getMonth());
  assertEquals(02, date.getDate());

  assertTrue(parser3.parse('991202', date) > 0);
  assertEquals(99, date.getFullYear());
  assertEquals(12 - 1, date.getMonth());
  assertEquals(02, date.getDate());

  assertTrue(parser3.parse('91202', date) > 0);
  assertEquals(9, date.getFullYear());
  assertEquals(12 - 1, date.getMonth());
  assertEquals(02, date.getDate());
}

function testYearParsing() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('yyMMdd');
  assertTrue(parser.parse('991202', date) > 0);
  assertEquals(1999, date.getFullYear());
  assertEquals(12 - 1, date.getMonth());
  assertEquals(02, date.getDate());

  var parser2 = new goog.i18n.DateTimeParse('yyyyMMdd');
  assertTrue(parser2.parse('20051202', date) > 0);
  assertEquals(2005, date.getFullYear());
  assertEquals(12 - 1, date.getMonth());
  assertEquals(02, date.getDate());
}

function testGoogDateParsing() {
  var date = new goog.date.Date();

  var parser = new goog.i18n.DateTimeParse('yyMMdd');
  assertTrue(parser.parse('991202', date) > 0);
  assertEquals(1999, date.getFullYear());
  assertEquals(12 - 1, date.getMonth());
  assertEquals(02, date.getDate());
}

function testHourParsing_hh() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('hhmm');
  assertTrue(parser.parse('0022', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('1122', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('1222', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('2322', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('2422', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  var parser2 = new goog.i18n.DateTimeParse('hhmma');
  assertTrue(parser2.parse('0022am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1122am', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1222am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2322am', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2422am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('0022pm', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1122pm', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1222pm', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2322pm', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2422pm', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());
}

function testHourParsing_KK() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('KKmm');
  assertTrue(parser.parse('0022', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('1122', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('1222', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('2322', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('2422', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());


  var parser2 = new goog.i18n.DateTimeParse('KKmma');
  assertTrue(parser2.parse('0022am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1122am', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1222am', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2322am', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2422am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('0022pm', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1122pm', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1222pm', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2322pm', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2422pm', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());
}

function testHourParsing_kk() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('kkmm');
  assertTrue(parser.parse('0022', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('1122', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('1222', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('2322', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('2422', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  var parser2 = new goog.i18n.DateTimeParse('kkmma');
  assertTrue(parser2.parse('0022am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1122am', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1222am', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2322am', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2422am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('0022pm', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1122pm', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1222pm', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2322pm', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2422pm', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());
}

function testHourParsing_HH() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('HHmm');
  assertTrue(parser.parse('0022', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('1122', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('1222', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('2322', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser.parse('2422', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  var parser2 = new goog.i18n.DateTimeParse('HHmma');
  assertTrue(parser2.parse('0022am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1122am', date) > 0);
  assertEquals(11, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1222am', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2322am', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2422am', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('0022pm', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1122pm', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('1222pm', date) > 0);
  assertEquals(12, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2322pm', date) > 0);
  assertEquals(23, date.getHours());
  assertEquals(22, date.getMinutes());

  assertTrue(parser2.parse('2422pm', date) > 0);
  assertEquals(00, date.getHours());
  assertEquals(22, date.getMinutes());
}

function testEnglishDate() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('yyyy MMM dd hh:mm');

  // Fails in Safari4/Chrome Winxp because of infrastructure issues, temporarily
  // disabled. See b/4274778.
  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
  try {
    assertTrue(parser.parse('2006 Jul 10 15:44', date) > 0);
    assertEquals(2006, date.getFullYear());
    assertEquals(7 - 1, date.getMonth());
    assertEquals(10, date.getDate());
    assertEquals(15, date.getHours());
    assertEquals(44, date.getMinutes());
  } catch(e) {
    expectedFailures.handleException(e);
  }
}

function testChineseDate() {
  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_zh;

  // Javascript month start from 0, July is 7 - 1
  var date = new Date(2006, 7 - 1, 24, 12, 12, 12, 0);
  var formatter = new goog.i18n.DateTimeFormat(
      goog.i18n.DateTimeFormat.Format.FULL_DATE);
  date_str = formatter.format(date);
  var parser = new goog.i18n.DateTimeParse(
      goog.i18n.DateTimeFormat.Format.FULL_DATE);

  parser.parse(date_str, date);
  assertEquals(2006, date.getFullYear());
  assertEquals(7 - 1, date.getMonth());
  assertEquals(24, date.getDate());

  parser = new goog.i18n.DateTimeParse(
      goog.i18n.DateTimeFormat.Format.LONG_DATE);
  parser.parse('2006\u5E747\u670824\u65E5', date);
  assertEquals(2006, date.getFullYear());
  assertEquals(7 - 1, date.getMonth());
  assertEquals(24, date.getDate());

  parser = new goog.i18n.DateTimeParse(
      goog.i18n.DateTimeFormat.Format.FULL_TIME);
  parser.parse('GMT-07:00\u4E0B\u534803\u65F626\u520628\u79D2', date);

  // Fails in Safari4/Chrome Winxp because of infrastructure issues, temporarily
  // disabled. See b/4274778.
  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
  try {
    assertEquals(22, (24 + date.getHours() + date.getTimezoneOffset()/60) % 24);
    assertEquals(26, date.getMinutes());
    assertEquals(28, date.getSeconds());
  } catch(e) {
    expectedFailures.handleException(e);
  }

  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_en;
}

// For languages with goog.i18n.DateTimeSymbols.ZERODIGIT defined, the int
// digits are localized by the locale in datetimeformat.js. This test case is
// for parsing dates with such native digits.
function testDatesWithNativeDigits() {
  // Language Arabic is one example with
  // goog.i18n.DateTimeSymbols.ZERODIGIT defined.
  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_fa;

  // Javascript month starts from 0, July is 7 - 1
  var date = new Date(2006, 7 - 1, 24, 12, 12, 12, 0);
  var formatter = new goog.i18n.DateTimeFormat(
      goog.i18n.DateTimeFormat.Format.FULL_DATE);
  date_str = formatter.format(date);
  var parser = new goog.i18n.DateTimeParse(
      goog.i18n.DateTimeFormat.Format.FULL_DATE);

  parser.parse(date_str, date);
  assertEquals(2006, date.getFullYear());
  assertEquals(7 - 1, date.getMonth());
  assertEquals(24, date.getDate());

  date = new Date(2006, 7 - 1, 24);
  formatter = new goog.i18n.DateTimeFormat(
      goog.i18n.DateTimeFormat.Format.SHORT_DATE);
  date_str = formatter.format(date);
  parser = new goog.i18n.DateTimeParse(
      goog.i18n.DateTimeFormat.Format.SHORT_DATE);

  parser.parse(date_str, date);
  assertEquals(2006, date.getFullYear());
  assertEquals(7 - 1, date.getMonth());
  assertEquals(24, date.getDate());

  date = new Date();

  parser = new goog.i18n.DateTimeParse('y/MM/dd H:mm:ss٫SS');
  assertTrue(parser.parse('۲۰۰۶/۰۷/۲۷ ۱۳:۱۰:۱۰٫۲۵', date) > 0);
  assertEquals(2006, date.getFullYear());
  assertEquals(6, date.getMonth());
  assertEquals(27, date.getDate());

  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_en;
}

function testTimeZone() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('MM/dd/yyyy, hh:mm:ss zzz');
  assertTrue(parser.parse('07/21/2003, 11:22:33 GMT-0700', date) > 0);
  var hourGmtMinus07 = date.getHours();

  assertTrue(parser.parse('07/21/2003, 11:22:33 GMT-0600', date) > 0);
  var hourGmtMinus06 = date.getHours();
  assertEquals(1, (hourGmtMinus07 + 24 - hourGmtMinus06) % 24);

  assertTrue(parser.parse('07/21/2003, 11:22:33 GMT-0800', date) > 0);
  var hourGmtMinus08 = date.getHours();
  assertEquals(1, (hourGmtMinus08 + 24 - hourGmtMinus07) % 24);

  assertTrue(parser.parse('07/21/2003, 23:22:33 GMT-0800', date) > 0);
  assertEquals((date.getHours() + 24 - hourGmtMinus07) % 24, 13);

  assertTrue(parser.parse('07/21/2003, 11:22:33 GMT+0800', date) > 0);
  var hourGmt08 = date.getHours();
  assertEquals(16, (hourGmtMinus08 + 24 - hourGmt08) % 24);

  assertTrue(parser.parse('07/21/2003, 11:22:33 GMT0800', date) > 0);
  assertEquals(hourGmt08, date.getHours());
}

function testWeekDay() {
  var date = new Date();
  var parser = new goog.i18n.DateTimeParse('EEEE, MM/dd/yyyy');

  assertTrue(parser.parse('Wednesday, 08/16/2006', date) > 0);
  assertEquals(2006, date.getFullYear());
  assertEquals(8 - 1, date.getMonth());
  assertEquals(16, date.getDate());
  assertTrue(parser.parse('Tuesday, 08/16/2006', date) == 0);
  assertTrue(parser.parse('Thursday, 08/16/2006', date) == 0);
  assertTrue(parser.parse('Wed, 08/16/2006', date) > 0);
  assertTrue(parser.parse('Wasdfed, 08/16/2006', date) == 0);

  date.setDate(25);
  parser = new goog.i18n.DateTimeParse('EEEE, MM/yyyy');
  assertTrue(parser.parse('Wed, 09/2006', date) > 0);
  assertEquals(27, date.getDate());

  date.setDate(30);
  assertTrue(parser.parse('Wed, 09/2006', date) > 0);
  assertEquals(27, date.getDate());
  date.setDate(30);
  assertTrue(parser.parse('Mon, 09/2006', date) > 0);
  assertEquals(25, date.getDate());
}

function testStrictParse() {
  var date = new Date();

  var parser = new goog.i18n.DateTimeParse('yyyy/MM/dd');
  assertTrue(parser.strictParse('2000/13/10', date) == 0);
  assertTrue(parser.strictParse('2000/13/40', date) == 0);
  assertTrue(parser.strictParse('2000/11/10', date) > 0);
  assertEquals(2000, date.getFullYear());
  assertEquals(11 - 1, date.getMonth());
  assertEquals(10, date.getDate());

  parser = new goog.i18n.DateTimeParse('yy/MM/dd');
  assertTrue(parser.strictParse('00/11/10', date) > 0);
  assertTrue(parser.strictParse('99/11/10', date) > 0);
  assertTrue(parser.strictParse('00/13/10', date) == 0);
  assertTrue(parser.strictParse('00/11/32', date) == 0);
  assertTrue(parser.strictParse('1900/11/2', date) > 0);


  parser = new goog.i18n.DateTimeParse('hh:mm');
  assertTrue(parser.strictParse('15:44', date) > 0);
  assertTrue(parser.strictParse('25:44', date) == 0);
  assertTrue(parser.strictParse('15:64', date) == 0);

  // leap year
  parser = new goog.i18n.DateTimeParse('yy/MM/dd');
  assertTrue(parser.strictParse('00/02/29', date) > 0);
  assertTrue(parser.strictParse('01/02/29', date) == 0);
}

function testEnglishQuarter() {
  var date = new Date();
  var parser = new goog.i18n.DateTimeParse('QQQQ yyyy');

  // Fails in Safari4/Chrome Winxp because of infrastructure issues, temporarily
  // disabled. See b/4274778.
  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
  try {
    assertTrue(parser.parse('1st quarter 2009', date) > 0);
    assertEquals(2009, date.getFullYear());
    assertEquals(0, date.getMonth());
    assertEquals(1, date.getDate());
  } catch(e) {
    expectedFailures.handleException(e);
  }
}

function testEnglishShortQuarter() {
  var date = new Date();
  var parser = new goog.i18n.DateTimeParse('yyyyQQ');

  // Fails in Safari4/Chrome Winxp because of infrastructure issues, temporarily
  // disabled. See b/4274778.
  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
  try {
    assertTrue(parser.parse('2006Q2', date) > 0);
    assertEquals(2006, date.getFullYear());
    assertEquals(4 - 1, date.getMonth());
    assertEquals(1, date.getDate());
  } catch(e) {
    expectedFailures.handleException(e);
  }
}

function testFrenchShortQuarter() {
  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_fr;

  var date = new Date();
  try {
    var parser = new goog.i18n.DateTimeParse('yyyyQQ');
    assertTrue(parser.parse('2009T3', date) > 0);
    assertEquals(2009, date.getFullYear());
    assertEquals(7 - 1, date.getMonth());
    assertEquals(1, date.getDate());
  } catch (e) {
    goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_en;
    throw e;
  }
  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_en;
}


</script>
</body>
</html>
